package cz.data.common.support.metadata;

import cz.data.common.support.DataTypeEnum;
import cz.data.common.support.FormatConstant;
import lombok.Getter;

@Getter
public enum JavaTypeEnum implements DataTypeEnum {

    STRING("string", "字符串"),
    TEXT("text", "长文本"),
    BYTE("byte", "单字节"),
    SHORT("short", "短整型"),
    INT("integer", "整型"),
    LONG("long", "长整型"),
    FLOAT("float", "单精度浮点"),
    DOUBLE("double", "双精度浮点", FormatConstant.DOUBLE_FORMATS),
    BOOLEAN("boolean", "布尔值"),
    BINARY("binary", "二进制"),
    DATE("date", "日期", FormatConstant.DATE_FORMATS),
    TIMESTAMP("timestamp", "时间戳"),
    OBJECT("map", "对象"),
    ARRAY("array", "数组"),
    LIST("list", "列表");

    private final String name;
    private final String describe;
    private final String[] formats;

    JavaTypeEnum(String name, String describe) {
        this(name, describe, new String[0]);
    }

    JavaTypeEnum(String name, String describe, String[] formats) {
        this.name = name;
        this.describe = describe;
        this.formats = formats;
    }


    public boolean matchName(String name) {
        return this.name.equalsIgnoreCase(name);
    }

    public static JavaTypeEnum match(String name) {
        for (JavaTypeEnum value : JavaTypeEnum.values()) {
            if (value.matchName(name)) {
                return value;
            }
        }
        return STRING;
    }

    @Override
    public String getValue() {
        return name;
    }

    @Override
    public String getTitle() {
        return describe;
    }
}
